//
//  SAServiceMarketView.m
//  saasRetail
//
//  Created by ice on 2024/9/26.
//

#import "SAServiceMarketView.h"
#import "SAServiceMarketModel.h"
#import "UILabel+NSMutableAttributedString.h"

@interface SAServiceMarketView ()

@property (nonatomic, strong) SAServiceMarketModel *marketingModel;

@end

@implementation SAServiceMarketView

-(instancetype)initWithFrame:(CGRect)frame AndModel:(SAServiceMarketModel *)model {
    if (self = [super initWithFrame:frame]) {
        self.marketingModel = model;
        [self initUI];
    }
    return self;
}


#pragma mark - event
-(void)clickedBgBtn {
    [self removeFromSuperview];
}

-(void)clickedPayBtn {
    !self.payBlock ?: self.payBlock();
    [self clickedBgBtn];
}

#pragma mark - initUI
-(void)initUI {
    
    UIView *bgView = [UIView new];
    bgView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.backgroundColor = kColor(0, 0, 0, 0.6);
    [self addSubview:bgView];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, (kScreenHeight - kScaleNum(472))/2, kScreenWidth, kScaleNum(446))];
    imageV.image = [UIImage imageNamed:@"kaitongvip_img_bg"];
    imageV.userInteractionEnabled = YES;
    [bgView addSubview:imageV];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    closeBtn.frame = CGRectMake((kScreenWidth - kScaleNum(26))/2, (kScreenHeight - kScaleNum(472))/2 + kScaleNum(446), kScaleNum(26), kScaleNum(26));
    [closeBtn addTarget:self action:@selector(clickedBgBtn) forControlEvents:UIControlEventTouchUpInside];
    [closeBtn setImage:[UIImage imageNamed:@"kaitongvip_close"] forState:UIControlStateNormal];
    [bgView addSubview:closeBtn];
    
    UILabel *trialLab = [[UILabel alloc] initWithFrame:CGRectMake(0, kScaleNum(140), kScreenWidth, kScaleNum(30))];
    trialLab.text = @"开通会员享8大优惠";
    trialLab.font = kBFont(22);
    trialLab.textColor = kColor(92, 9, 11, 1);
    trialLab.textAlignment = NSTextAlignmentCenter;
    [imageV addSubview:trialLab];
    [trialLab setAttributedStringWithSubString:@"8" color:[UIColor redColor] font:kBFont(22)];

    UILabel *tipLab =  [[UILabel alloc] initWithFrame:CGRectMake(0, kScaleNum(175), kScreenWidth, kScaleNum(20))];
    tipLab.text = [NSString stringWithFormat:@"支付%@",self.marketingModel.descriptionStr];
    tipLab.font = kFont(18);
    tipLab.textColor = [UIColor redColor];
    tipLab.textAlignment = NSTextAlignmentCenter;
    [imageV addSubview:tipLab];
    [tipLab setAttributedStringWithSubString:@"支付费率低至" color:kColor(92, 9, 11, 1) font:kFont(18)];
    
    UIButton *payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [payBtn setTitle:@"立即开通" forState:UIControlStateNormal];
    [payBtn setTitleColor:kColor(92, 9, 11, 1) forState:UIControlStateNormal];
    payBtn.titleLabel.font = kBFont(20);
    payBtn.frame = CGRectMake((kScreenWidth - kScaleNum(200))/2, kScaleNum(340), kScaleNum(200), kScaleNum(44));
    [payBtn addTarget:self action:@selector(clickedPayBtn) forControlEvents:UIControlEventTouchUpInside];
    payBtn.backgroundColor = kColor(240, 190, 90, 1);
    payBtn.layer.masksToBounds = YES;
    payBtn.layer.cornerRadius = kScaleNum(22);
    [imageV addSubview:payBtn];

}

@end

